
import threading
import time

event = threading.Event()


def func():
    # 等待事件，进入等待阻塞状态
    print("{} waiting for event...".format(threading.current_thread().getName()))
    event.wait()
    # 收到事件后，进入运行状态
    print("{} receving event.\n".format(threading.current_thread().getName()))


t1 = threading.Thread(target=func)
t2 = threading.Thread(target=func)
t1.start()
t2.start()

time.sleep(2)

# 发送事件通知
print('MainThread set event.')
event.set()

"""
OUTPUT:
Thread-1 waiting for event...
Thread-2 waiting for event...
MainThread set event.
Thread-2 receving event.
Thread-1 receving event.
"""